.class Ljavax/microedition/media/MidiAudioPlayer;
.super Ljava/lang/Object;
.source "MidiAudioPlayer.java"

# interfaces
.implements Ljavax/microedition/media/Player;
.implements Ljavax/sound/midi/MetaEventListener;


# instance fields
.field private iLoopCount:I

.field private sequence:Ljavax/sound/midi/Sequence;

.field private sequencer:Ljavax/sound/midi/Sequencer;

.field private vListeners:Ljava/util/Vector;


# direct methods
.method constructor <init>()V
    .locals 1

    .prologue
    const/4 v0, 0x0

    .line 43
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 45
    iput-object v0, p0, Ljavax/microedition/media/MidiAudioPlayer;->sequence:Ljavax/sound/midi/Sequence;

    .line 46
    iput-object v0, p0, Ljavax/microedition/media/MidiAudioPlayer;->sequencer:Ljavax/sound/midi/Sequencer;

    .line 47
    iput-object v0, p0, Ljavax/microedition/media/MidiAudioPlayer;->vListeners:Ljava/util/Vector;

    .line 48
    const/4 v0, 0x1

    iput v0, p0, Ljavax/microedition/media/MidiAudioPlayer;->iLoopCount:I

    return-void
.end method


# virtual methods
.method public addPlayerListener(Ljavax/microedition/media/PlayerListener;)V
    .locals 1
    .parameter "playerListener"

    .prologue
    .line 83
    iget-object v0, p0, Ljavax/microedition/media/MidiAudioPlayer;->vListeners:Ljava/util/Vector;

    if-nez v0, :cond_0

    .line 84
    new-instance v0, Ljava/util/Vector;

    invoke-direct {v0}, Ljava/util/Vector;-><init>()V

    iput-object v0, p0, Ljavax/microedition/media/MidiAudioPlayer;->vListeners:Ljava/util/Vector;

    .line 85
    :cond_0
    iget-object v0, p0, Ljavax/microedition/media/MidiAudioPlayer;->vListeners:Ljava/util/Vector;

    invoke-virtual {v0, p1}, Ljava/util/Vector;->add(Ljava/lang/Object;)Z

    .line 86
    return-void
.end method

.method public close()V
    .locals 1

    .prologue
    .line 90
    invoke-static {p0}, Ljavax/microedition/media/Manager;->mediaDone(Ljava/lang/Object;)V

    .line 91
    iget-object v0, p0, Ljavax/microedition/media/MidiAudioPlayer;->sequencer:Ljavax/sound/midi/Sequencer;

    if-eqz v0, :cond_0

    .line 92
    iget-object v0, p0, Ljavax/microedition/media/MidiAudioPlayer;->sequencer:Ljavax/sound/midi/Sequencer;

    invoke-interface {v0}, Ljavax/sound/midi/Sequencer;->close()V

    .line 93
    :cond_0
    return-void
.end method

.method public deallocate()V
    .locals 0

    .prologue
    .line 96
    return-void
.end method

.method protected dispose()V
    .locals 0

    .prologue
    .line 78
    invoke-virtual {p0}, Ljavax/microedition/media/MidiAudioPlayer;->close()V

    .line 79
    return-void
.end method

.method public getContentType()Ljava/lang/String;
    .locals 1

    .prologue
    .line 99
    const-string v0, "audio/midi"

    return-object v0
.end method

.method public getControl(Ljava/lang/String;)Ljavax/microedition/media/Control;
    .locals 1
    .parameter "controlType"

    .prologue
    .line 169
    const/4 v0, 0x0

    return-object v0
.end method

.method public getControls()[Ljavax/microedition/media/Control;
    .locals 1

    .prologue
    .line 174
    const/4 v0, 0x0

    return-object v0
.end method

.method public getDuration()J
    .locals 2

    .prologue
    .line 103
    const-wide/16 v0, 0x0

    return-wide v0
.end method

.method public getMediaTime()J
    .locals 2

    .prologue
    .line 108
    iget-object v0, p0, Ljavax/microedition/media/MidiAudioPlayer;->sequencer:Ljavax/sound/midi/Sequencer;

    if-eqz v0, :cond_0

    .line 109
    iget-object v0, p0, Ljavax/microedition/media/MidiAudioPlayer;->sequencer:Ljavax/sound/midi/Sequencer;

    invoke-interface {v0}, Ljavax/sound/midi/Sequencer;->getMicrosecondPosition()J

    move-result-wide v0

    .line 110
    :goto_0
    return-wide v0

    :cond_0
    const-wide/16 v0, 0x0

    goto :goto_0
.end method

.method public getState()I
    .locals 1

    .prologue
    .line 115
    const/4 v0, 0x0

    return v0
.end method

.method public meta(Ljavax/sound/midi/MetaMessage;)V
    .locals 6
    .parameter "event"

    .prologue
    .line 179
    invoke-virtual {p1}, Ljavax/sound/midi/MetaMessage;->getType()I

    move-result v3

    const/16 v4, 0x2f

    if-ne v3, v4, :cond_2

    .line 181
    iget v3, p0, Ljavax/microedition/media/MidiAudioPlayer;->iLoopCount:I

    if-lez v3, :cond_0

    .line 183
    iget v3, p0, Ljavax/microedition/media/MidiAudioPlayer;->iLoopCount:I

    const/4 v4, 0x1

    sub-int/2addr v3, v4

    iput v3, p0, Ljavax/microedition/media/MidiAudioPlayer;->iLoopCount:I

    .line 185
    :cond_0
    iget v3, p0, Ljavax/microedition/media/MidiAudioPlayer;->iLoopCount:I

    if-gtz v3, :cond_1

    iget v3, p0, Ljavax/microedition/media/MidiAudioPlayer;->iLoopCount:I

    const/4 v4, -0x1

    if-ne v3, v4, :cond_3

    .line 187
    :cond_1
    iget-object v3, p0, Ljavax/microedition/media/MidiAudioPlayer;->sequencer:Ljavax/sound/midi/Sequencer;

    const-wide/16 v4, 0x0

    invoke-interface {v3, v4, v5}, Ljavax/sound/midi/Sequencer;->setMicrosecondPosition(J)V

    .line 188
    :try_start_0
    invoke-virtual {p0}, Ljavax/microedition/media/MidiAudioPlayer;->start()V
    :try_end_0
    .catch Ljavax/microedition/media/MediaException; {:try_start_0 .. :try_end_0} :catch_0

    .line 204
    :cond_2
    :goto_0
    return-void

    .line 189
    :catch_0
    move-exception v0

    .local v0, e:Ljavax/microedition/media/MediaException;
    invoke-virtual {v0}, Ljavax/microedition/media/MediaException;->printStackTrace()V

    goto :goto_0

    .line 193
    .end local v0           #e:Ljavax/microedition/media/MediaException;
    :cond_3
    invoke-virtual {p0}, Ljavax/microedition/media/MidiAudioPlayer;->close()V

    .line 194
    iget-object v3, p0, Ljavax/microedition/media/MidiAudioPlayer;->vListeners:Ljava/util/Vector;

    if-eqz v3, :cond_2

    .line 196
    iget-object v3, p0, Ljavax/microedition/media/MidiAudioPlayer;->vListeners:Ljava/util/Vector;

    invoke-virtual {v3}, Ljava/util/Vector;->iterator()Ljava/util/Iterator;

    move-result-object v1

    .local v1, it:Ljava/util/Iterator;
    :goto_1
    invoke-interface {v1}, Ljava/util/Iterator;->hasNext()Z

    move-result v3

    if-eqz v3, :cond_2

    .line 198
    invoke-interface {v1}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v2

    check-cast v2, Ljavax/microedition/media/PlayerListener;

    .line 199
    .local v2, listener:Ljavax/microedition/media/PlayerListener;
    const-string v3, "endOfMedia"

    const/4 v4, 0x0

    invoke-interface {v2, p0, v3, v4}, Ljavax/microedition/media/PlayerListener;->playerUpdate(Ljavax/microedition/media/Player;Ljava/lang/String;Ljava/lang/Object;)V

    goto :goto_1
.end method

.method public open(Ljava/io/InputStream;Ljava/lang/String;)Z
    .locals 6
    .parameter "stream"
    .parameter "type"

    .prologue
    .line 56
    :try_start_0
    invoke-static {}, Ljavax/sound/midi/MidiSystem;->getSequencer()Ljavax/sound/midi/Sequencer;

    move-result-object v4

    iput-object v4, p0, Ljavax/microedition/media/MidiAudioPlayer;->sequencer:Ljavax/sound/midi/Sequencer;

    .line 57
    iget-object v4, p0, Ljavax/microedition/media/MidiAudioPlayer;->sequencer:Ljavax/sound/midi/Sequencer;

    invoke-interface {v4}, Ljavax/sound/midi/Sequencer;->open()V

    .line 59
    invoke-static {}, Ljavax/sound/midi/MidiSystem;->getSynthesizer()Ljavax/sound/midi/Synthesizer;

    move-result-object v2

    .line 60
    .local v2, synth:Ljavax/sound/midi/Synthesizer;
    invoke-interface {v2}, Ljavax/sound/midi/Synthesizer;->open()V

    .line 63
    iget-object v4, p0, Ljavax/microedition/media/MidiAudioPlayer;->sequencer:Ljavax/sound/midi/Sequencer;

    invoke-interface {v4}, Ljavax/sound/midi/Sequencer;->getTransmitter()Ljavax/sound/midi/Transmitter;

    move-result-object v3

    .line 64
    .local v3, transmitter:Ljavax/sound/midi/Transmitter;
    invoke-interface {v2}, Ljavax/sound/midi/Synthesizer;->getReceiver()Ljavax/sound/midi/Receiver;

    move-result-object v1

    .line 65
    .local v1, receiver:Ljavax/sound/midi/Receiver;
    invoke-interface {v3, v1}, Ljavax/sound/midi/Transmitter;->setReceiver(Ljavax/sound/midi/Receiver;)V

    .line 67
    invoke-static {p1}, Ljavax/sound/midi/MidiSystem;->getSequence(Ljava/io/InputStream;)Ljavax/sound/midi/Sequence;

    move-result-object v4

    iput-object v4, p0, Ljavax/microedition/media/MidiAudioPlayer;->sequence:Ljavax/sound/midi/Sequence;

    .line 68
    iget-object v4, p0, Ljavax/microedition/media/MidiAudioPlayer;->sequencer:Ljavax/sound/midi/Sequencer;

    iget-object v5, p0, Ljavax/microedition/media/MidiAudioPlayer;->sequence:Ljavax/sound/midi/Sequence;

    invoke-interface {v4, v5}, Ljavax/sound/midi/Sequencer;->setSequence(Ljavax/sound/midi/Sequence;)V
    :try_end_0
    .catch Ljava/io/IOException; {:try_start_0 .. :try_end_0} :catch_0
    .catch Ljavax/sound/midi/MidiUnavailableException; {:try_start_0 .. :try_end_0} :catch_1
    .catch Ljavax/sound/midi/InvalidMidiDataException; {:try_start_0 .. :try_end_0} :catch_2

    .line 73
    .end local v2           #synth:Ljavax/sound/midi/Synthesizer;
    .end local v3           #transmitter:Ljavax/sound/midi/Transmitter;
    .end local v1           #receiver:Ljavax/sound/midi/Receiver;
    :goto_0
    const/4 v4, 0x0

    return v4

    .line 70
    :catch_0
    move-exception v4

    move-object v0, v4

    .local v0, e:Ljava/io/IOException;
    invoke-virtual {v0}, Ljava/io/IOException;->printStackTrace()V

    goto :goto_0

    .line 71
    .end local v0           #e:Ljava/io/IOException;
    :catch_1
    move-exception v4

    move-object v0, v4

    .local v0, e:Ljavax/sound/midi/MidiUnavailableException;
    invoke-virtual {v0}, Ljavax/sound/midi/MidiUnavailableException;->printStackTrace()V

    goto :goto_0

    .line 72
    .end local v0           #e:Ljavax/sound/midi/MidiUnavailableException;
    :catch_2
    move-exception v4

    move-object v0, v4

    .local v0, e:Ljavax/sound/midi/InvalidMidiDataException;
    invoke-virtual {v0}, Ljavax/sound/midi/InvalidMidiDataException;->printStackTrace()V

    goto :goto_0
.end method

.method public prefetch()V
    .locals 0
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljavax/microedition/media/MediaException;
        }
    .end annotation

    .prologue
    .line 121
    return-void
.end method

.method public realize()V
    .locals 0
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljavax/microedition/media/MediaException;
        }
    .end annotation

    .prologue
    .line 126
    return-void
.end method

.method public removePlayerListener(Ljavax/microedition/media/PlayerListener;)V
    .locals 3
    .parameter "playerListener"

    .prologue
    .line 130
    iget-object v2, p0, Ljavax/microedition/media/MidiAudioPlayer;->vListeners:Ljava/util/Vector;

    if-nez v2, :cond_1

    .line 141
    :cond_0
    :goto_0
    return-void

    .line 132
    :cond_1
    iget-object v2, p0, Ljavax/microedition/media/MidiAudioPlayer;->vListeners:Ljava/util/Vector;

    invoke-virtual {v2}, Ljava/util/Vector;->iterator()Ljava/util/Iterator;

    move-result-object v0

    .local v0, it:Ljava/util/Iterator;
    :cond_2
    invoke-interface {v0}, Ljava/util/Iterator;->hasNext()Z

    move-result v2

    if-eqz v2, :cond_0

    .line 134
    invoke-interface {v0}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v1

    check-cast v1, Ljavax/microedition/media/PlayerListener;

    .line 135
    .local v1, listener:Ljavax/microedition/media/PlayerListener;
    if-ne v1, p1, :cond_2

    .line 137
    iget-object v2, p0, Ljavax/microedition/media/MidiAudioPlayer;->vListeners:Ljava/util/Vector;

    invoke-virtual {v2, v1}, Ljava/util/Vector;->remove(Ljava/lang/Object;)Z

    goto :goto_0
.end method

.method public setLoopCount(I)V
    .locals 0
    .parameter "count"

    .prologue
    .line 145
    iput p1, p0, Ljavax/microedition/media/MidiAudioPlayer;->iLoopCount:I

    .line 146
    return-void
.end method

.method public setMediaTime(J)J
    .locals 1
    .parameter "now"
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljavax/microedition/media/MediaException;
        }
    .end annotation

    .prologue
    .line 149
    iget-object v0, p0, Ljavax/microedition/media/MidiAudioPlayer;->sequencer:Ljavax/sound/midi/Sequencer;

    if-eqz v0, :cond_0

    .line 150
    iget-object v0, p0, Ljavax/microedition/media/MidiAudioPlayer;->sequencer:Ljavax/sound/midi/Sequencer;

    invoke-interface {v0, p1, p2}, Ljavax/sound/midi/Sequencer;->setMicrosecondPosition(J)V

    .line 151
    :cond_0
    return-wide p1
.end method

.method public start()V
    .locals 1
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljavax/microedition/media/MediaException;
        }
    .end annotation

    .prologue
    .line 155
    iget-object v0, p0, Ljavax/microedition/media/MidiAudioPlayer;->sequencer:Ljavax/sound/midi/Sequencer;

    if-eqz v0, :cond_0

    .line 157
    iget-object v0, p0, Ljavax/microedition/media/MidiAudioPlayer;->sequencer:Ljavax/sound/midi/Sequencer;

    invoke-interface {v0, p0}, Ljavax/sound/midi/Sequencer;->addMetaEventListener(Ljavax/sound/midi/MetaEventListener;)Z

    .line 158
    iget-object v0, p0, Ljavax/microedition/media/MidiAudioPlayer;->sequencer:Ljavax/sound/midi/Sequencer;

    invoke-interface {v0}, Ljavax/sound/midi/Sequencer;->start()V

    .line 160
    :cond_0
    return-void
.end method

.method public stop()V
    .locals 1
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljavax/microedition/media/MediaException;
        }
    .end annotation

    .prologue
    .line 163
    iget-object v0, p0, Ljavax/microedition/media/MidiAudioPlayer;->sequencer:Ljavax/sound/midi/Sequencer;

    if-eqz v0, :cond_0

    .line 164
    iget-object v0, p0, Ljavax/microedition/media/MidiAudioPlayer;->sequencer:Ljavax/sound/midi/Sequencer;

    invoke-interface {v0}, Ljavax/sound/midi/Sequencer;->stop()V

    .line 165
    :cond_0
    return-void
.end method
